package com.wealth.member.web.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wealth.coupon.entity.CouponRecord;
import com.wealth.coupon.service.ICouponRecordService;
import com.wealth.system.web.controller.BaseController;

/**
 * 惠生活 - 优惠券
 * 
 * @author chan
 */
@Controller
@RequestMapping(value="/coupon")
public class CouponController extends BaseController{

	Logger logger = Logger.getLogger(CouponController.class);
	
	@Autowired
	private ICouponRecordService couponRecordService;
	
	/** 
	 * 查询优惠券
	 */
	@RequestMapping(value="/search",method=RequestMethod.POST)
	@ResponseBody
	public List<CouponRecord> search(Model model,@RequestParam Long memberid,@RequestParam Double total) {
		try{
			List<CouponRecord> couponRecordList= couponRecordService.getUsableCouponRecord(memberid, total);
			return couponRecordList;
		}catch(Exception e){
			return null;
		}
	}
	
	
	/** 
	 * 列表页面
	 */
	@RequestMapping
	public String listForm(Model model,@RequestParam(required=false) Integer status) {
		try{
			//如果不传入参数status = null
			List<CouponRecord> couponRecordList= couponRecordService.getCouponRecordByMemberIdAndStatus(memberid, status);
			model.addAttribute("couponRecordList", couponRecordList);
			model.addAttribute("status", status);
			return "coupon/list";
		}catch(Exception e){
			return "system/500";
		}
	}
	
}
